package service;

import dao.VegetableAddDao;
import entity.Vegetable;
import util.DBMannager;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.sql.Date;
import java.util.Scanner;
import java.util.logging.SimpleFormatter;

public class addService {

    public static void main(String[] args) throws SQLException, ParseException {

        Connection connection= DBMannager.getConnection();
        VegetableAddDao vegetableAddDao = new VegetableAddDao();
        Vegetable vegetable = new Vegetable();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入蔬菜名称:");
        vegetable.setVegename(scanner.nextLine());
        System.out.println("(格式为yyyy-MM-dd)请输入种植日期:");
        Date date = null;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

            date = new Date(formatter.parse(scanner.nextLine()).getTime());
            new Date(date.getTime());
        } catch (ParseException e) {
            System.out.println("日期格式输入错误");
            return;
        }
//        } catch (ParseException e) {
//
//            System.out.println("日期格式输入错误");
//        }
//        Date date=new Date();
//        try {
//            date=new SimpleDateFormat("yyyy-MM-dd").parse(scanner.nextLine());
//        } catch (ParseException e) {
//            System.out.println("日期格式输入错误");
//            throw new RuntimeException(e);
//        }
        vegetable.setPlanttime(date);
        System.out.println("请输入蔬菜数量:");
        vegetable.setNumber(scanner.nextInt());
        System.out.println("请输入蔬菜单价:");
        vegetable.setPrice(scanner.nextBigDecimal());
        System.out.println("请输入蔬菜状态(0/1):");
        vegetable.setVstatus(scanner.nextInt());
        if(vegetableAddDao.addVegetable(vegetable)){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }


    }

}
